import 'package:get_it/get_it.dart';
import 'package:mobile_app.core/injection_container.dart' as core_di;
import 'package:mobile_app.home.core/injection_container.dart' as home_core_di;
import 'package:mobile_app.home.learning.core/injection_container.dart' as learning_core_di;
import 'package:mobile_app.home.learning.training/training_page/domain/helpers/apply_all_lexical_item_mark_as_trained/helper.dart';
import 'package:mobile_app.home.learning.training/training_page/domain/helpers/apply_card_info_effective_image_path_setting/helper.dart';
import 'package:mobile_app.home.learning.training/training_page/domain/helpers/apply_card_info_pronunciation_safety_setting/helper.dart';
import 'package:mobile_app.home.learning.training/training_page/domain/helpers/create_exercise_card_info/helper.dart';
import 'package:mobile_app.home.learning.training/training_page/domain/helpers/get_effective_exercises/helper.dart';
import 'package:mobile_app.home.learning.training/training_page/domain/helpers/get_training_count/helper.dart';
import 'package:mobile_app.home.learning.training/training_page/domain/helpers/get_training_progress/helper.dart';
import 'package:mobile_app.home.learning.training/training_page/domain/helpers/handle_training_completion/helper.dart';
import 'package:mobile_app.home.learning.training/training_page/domain/helpers/is_app_review_request_reasonable/helper.dart';
import 'package:mobile_app.home.learning.training/training_page/domain/helpers/pick_next_exercise/helper.dart';
import 'package:mobile_app.home.learning.training/training_page/domain/use_cases/continue_learning/use_case.dart';
import 'package:mobile_app.home.learning.training/training_page/domain/use_cases/get_initial_data/use_case.dart';
import 'package:mobile_app.home.learning.training/training_page/domain/use_cases/handle_audio_card_failure/use_case.dart';
import 'package:mobile_app.home.learning.training/training_page/domain/use_cases/handle_audio_card_hint_usage/use_case.dart';
import 'package:mobile_app.home.learning.training/training_page/domain/use_cases/handle_audio_card_success/use_case.dart';
import 'package:mobile_app.home.learning.training/training_page/domain/use_cases/handle_cached_image_path_map_outer_update/use_case.dart';
import 'package:mobile_app.home.learning.training/training_page/domain/use_cases/handle_dialect_outer_update/use_case.dart';
import 'package:mobile_app.home.learning.training/training_page/domain/use_cases/handle_image_settings_outer_update/use_case.dart';
import 'package:mobile_app.home.learning.training/training_page/domain/use_cases/handle_initial_memorization_card_completion/use_case.dart';
import 'package:mobile_app.home.learning.training/training_page/domain/use_cases/handle_learning_content_outer_update/use_case.dart';
import 'package:mobile_app.home.learning.training/training_page/domain/use_cases/handle_subsequent_memorization_card_completion/use_case.dart';
import 'package:mobile_app.home.learning.training/training_page/domain/use_cases/handle_translation_selection_card_completion/use_case.dart';
import 'package:mobile_app.home.learning.training/training_page/domain/use_cases/handle_typing_card_failure/use_case.dart';
import 'package:mobile_app.home.learning.training/training_page/domain/use_cases/handle_typing_card_hint_usage/use_case.dart';
import 'package:mobile_app.home.learning.training/training_page/domain/use_cases/handle_typing_card_success/use_case.dart';
import 'package:mobile_app.home.learning.training/training_page/domain/use_cases/initialize/use_case.dart';
import 'package:mobile_app.home.learning.training/training_page/domain/use_cases/maybe_auto_pronounce_audio_card_lexical_item/use_case.dart';
import 'package:mobile_app.home.learning.training/training_page/domain/use_cases/maybe_auto_pronounce_initial_memorization_card_lexical_item/use_case.dart';
import 'package:mobile_app.home.learning.training/training_page/domain/use_cases/maybe_auto_pronounce_subsequent_memorization_card_lexical_item/use_case.dart';
import 'package:mobile_app.home.learning.training/training_page/domain/use_cases/maybe_auto_pronounce_translation_selection_card_lexical_item/use_case.dart';

final sl = GetIt.asNewInstance();

Future<void> init() async {
  // domain helpers

  sl.registerLazySingleton<ApplyAllLexicalItemMarkAsTrained>(() {
    return const ApplyAllLexicalItemMarkAsTrainedImpl();
  });

  sl.registerLazySingleton<ApplyCardInfoEffectiveImagePathSetting>(() {
    return ApplyCardInfoEffectiveImagePathSettingImpl(
      getLexicalItemEffectiveImagePath: home_core_di.sl(),
    );
  });

  sl.registerLazySingleton<ApplyCardInfoPronunciationSafetySetting>(() {
    return ApplyCardInfoPronunciationSafetySettingImpl(
      isLexicalItemSafeToPronounce: home_core_di.sl(),
    );
  });

  sl.registerLazySingleton<CreateExerciseCardInfo>(() {
    return CreateExerciseCardInfoImpl(
      isLexicalItemSafeToPronounce: home_core_di.sl(),
      getLexicalItemEffectiveImagePath: home_core_di.sl(),
      generateTranslationSelectionCardAnswerOptionLexicalItems: home_core_di.sl(),
    );
  });

  sl.registerLazySingleton<GetEffectiveExercises>(() {
    return const GetEffectiveExercisesImpl();
  });

  sl.registerLazySingleton<GetTrainingCount>(() {
    return const GetTrainingCountImpl();
  });

  sl.registerLazySingleton<GetTrainingProgress>(() {
    return const GetTrainingProgressImpl();
  });

  sl.registerLazySingleton<HandleTrainingCompletion>(() {
    return HandleTrainingCompletionImpl(
      userRepository: core_di.sl(),
      analyticsService: core_di.sl(),
      learningContentRepository: core_di.sl(),
      getLexicalItemProgressPercentMap: home_core_di.sl(),
      sortLexicalItems: home_core_di.sl(),
      applyAllLexicalItemMarkAsTrained: sl(),
      isAppReviewRequestReasonable: sl(),
    );
  });

  sl.registerLazySingleton<IsAppReviewRequestReasonable>(() {
    return IsAppReviewRequestReasonableImpl(
      getTrainingCount: sl(),
    );
  });

  sl.registerLazySingleton<PickNextExercise>(() {
    return const PickNextExerciseImpl();
  });

  // use cases

  sl.registerLazySingleton<ContinueLearning>(() {
    return ContinueLearningImpl(
      maybeBuildTrainingLexicalItems: learning_core_di.sl(),
    );
  });

  sl.registerLazySingleton<GetInitialData>(() {
    return GetInitialDataImpl(
      createExerciseCardInfo: sl(),
      getEffectiveExercises: sl(),
      pickNextExercise: sl(),
      imageService: core_di.sl(),
    );
  });

  sl.registerLazySingleton<HandleAudioCardFailure>(() {
    return HandleAudioCardFailureImpl(
      getLexicalItemEffectiveImagePath: home_core_di.sl(),
      imageService: core_di.sl(),
      handleLearningActivity: core_di.sl(),
    );
  });

  sl.registerLazySingleton<HandleAudioCardHintUsage>(() {
    return HandleAudioCardHintUsageImpl(
      handleLearningActivity: core_di.sl(),
    );
  });

  sl.registerLazySingleton<HandleAudioCardSuccess>(() {
    return HandleAudioCardSuccessImpl(
      imageService: core_di.sl(),
      createExerciseCardInfo: sl(),
      getTrainingProgress: sl(),
      handleTrainingCompletion: sl(),
      pickNextExercise: sl(),
      handleLearningActivity: core_di.sl(),
    );
  });

  sl.registerLazySingleton<HandleCachedImagePathMapOuterUpdate>(() {
    return HandleCachedImagePathMapOuterUpdateImpl(
      applyCardInfoEffectiveImagePathSetting: sl(),
    );
  });

  sl.registerLazySingleton<HandleDialectOuterUpdate>(() {
    return HandleDialectOuterUpdateImpl(
      applyCardInfoPronunciationSafetySetting: sl(),
    );
  });

  sl.registerLazySingleton<HandleImageSettingsOuterUpdate>(() {
    return HandleImageSettingsOuterUpdateImpl(
      applyCardInfoEffectiveImagePathSetting: sl(),
      imageService: core_di.sl(),
    );
  });

  sl.registerLazySingleton<HandleInitialMemorizationCardCompletion>(() {
    return HandleInitialMemorizationCardCompletionImpl(
      createExerciseCardInfo: sl(),
      getTrainingProgress: sl(),
      imageService: core_di.sl(),
      pickNextExercise: sl(),
      handleTrainingCompletion: sl(),
      handleLearningActivity: core_di.sl(),
    );
  });

  sl.registerLazySingleton<HandleLearningContentOuterUpdate>(() {
    return HandleLearningContentOuterUpdateImpl(
      applyCardInfoPronunciationSafetySetting: sl(),
    );
  });

  sl.registerLazySingleton<HandleSubsequentMemorizationCardCompletion>(() {
    return HandleSubsequentMemorizationCardCompletionImpl(
      createExerciseCardInfo: sl(),
      imageService: core_di.sl(),
      pickNextExercise: sl(),
      handleTrainingCompletion: sl(),
      handleLearningActivity: core_di.sl(),
    );
  });

  sl.registerLazySingleton<HandleTranslationSelectionCardCompletion>(() {
    return HandleTranslationSelectionCardCompletionImpl(
      createExerciseCardInfo: sl(),
      imageService: core_di.sl(),
      pickNextExercise: sl(),
      handleTrainingCompletion: sl(),
      getTrainingProgress: sl(),
      handleLearningActivity: core_di.sl(),
    );
  });

  sl.registerLazySingleton<HandleTypingCardFailure>(() {
    return HandleTypingCardFailureImpl(
      getLexicalItemEffectiveImagePath: home_core_di.sl(),
      imageService: core_di.sl(),
      isLexicalItemSafeToPronounce: home_core_di.sl(),
      handleLearningActivity: core_di.sl(),
    );
  });

  sl.registerLazySingleton<HandleTypingCardHintUsage>(() {
    return HandleTypingCardHintUsageImpl(
      handleLearningActivity: core_di.sl(),
    );
  });

  sl.registerLazySingleton<HandleTypingCardSuccess>(() {
    return HandleTypingCardSuccessImpl(
      imageService: core_di.sl(),
      createExerciseCardInfo: sl(),
      getTrainingProgress: sl(),
      handleTrainingCompletion: sl(),
      pickNextExercise: sl(),
      handleLearningActivity: core_di.sl(),
    );
  });

  sl.registerLazySingleton<Initialize>(() {
    return InitializeImpl(
      imageService: core_di.sl(),
      maybeStartLexicalItemImageDownload: home_core_di.sl(),
    );
  });

  sl.registerLazySingleton<MaybeAutoPronounceAudioCardLexicalItem>(() {
    return MaybeAutoPronounceAudioCardLexicalItemImpl(
      ttsService: core_di.sl(),
    );
  });

  sl.registerLazySingleton<MaybeAutoPronounceInitialMemorizationCardLexicalItem>(() {
    return MaybeAutoPronounceInitialMemorizationCardLexicalItemImpl(
      ttsService: core_di.sl(),
    );
  });

  sl.registerLazySingleton<MaybeAutoPronounceSubsequentMemorizationCardLexicalItem>(() {
    return MaybeAutoPronounceSubsequentMemorizationCardLexicalItemImpl(
      ttsService: core_di.sl(),
    );
  });

  sl.registerLazySingleton<MaybeAutoPronounceTranslationSelectionCardLexicalItem>(() {
    return MaybeAutoPronounceTranslationSelectionCardLexicalItemImpl(
      ttsService: core_di.sl(),
    );
  });
}
